//
//  EFHomeViewController.m
//  insurance
//
//  Created by 王长飞 on 2019/9/26.
//  Copyright © 2019年 王长飞. All rights reserved.
//

#import "HomeViewController.h"
#import "LoginViewController.h"
#import "InformationController.h"
#import "ProductDetailController.h"
#import "FriendsCodeController.h"
#import "AboutPlatformController.h"
#import "GoodsDetailController.h"
#import "ServiceClauseController.h"
#import "PrivcayClauseController.h"
#import "HomeBannerModel.h"
#import "HomeNavigationModel.h"
#import "HomeNoticeModel.h"
#import "HomeRecommendModel.h"
#import "EFAdView.h"
#import "HomeNavButton.h"
#import "KKNoticeView.h"
#import "JumpUtils.h"
#import "AppDelegate.h"

NSString *const guidePrivacySave = @"guidePrivacySave";

@interface HomeViewController ()<BaseModelProtocol,UIScrollViewDelegate,KKNoticeViewDelegate>

@property (nonatomic,strong)UIView *privacyCoverView;

@property (nonatomic,strong)HomeBannerModel *bannerModel ;
@property (nonatomic,strong)HomeNavigationModel *navigationModel ;
@property (nonatomic,strong)HomeNoticeModel *noticeModel ;
@property (nonatomic,strong)HomeRecommendModel *recommendModel;

@property (nonatomic,strong)UIView *bannerBgView ;
@property (nonatomic,strong)NSArray *bannerArray ;

@property (nonatomic,strong)UIScrollView *navigationScrollView ;
@property (nonatomic,strong)NSArray *navigationArray ;

@property (nonatomic,strong) UIView *noticeBgView;
@property (nonatomic,strong) UIView *noticeView;
@property (nonatomic,strong) NSArray *noticeArray;

@property (nonatomic,strong)UIScrollView *recommednScrollView ;
@property (nonatomic,strong)NSArray *recommendList;
// 资讯模块
@property (nonatomic,strong)NSArray *informationList;
// 标准电商
@property (nonatomic,strong)NSArray *shopProductList;
// 保险产品
@property (nonatomic,strong)NSArray *insuranceCangbaotuProductList;


@end

@implementation HomeViewController

//- (UIStatusBarStyle)preferredStatusBarStyle
//{
//    return UIStatusBarStyleDefault;
//}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//    [self navigationDragCanBack:YES];

    EFAppContext *appc = [EFAppContext sharedContext];
//    if (ISEMPTY(appc.authorization)) {
//        [self.privacyCoverView setHidden:YES];
//        LoginViewController *loginVC = [[LoginViewController alloc]init];
//        [self.navigationController pushViewController:loginVC animated:YES];
//    }else{
        //获取banner配置：首页工作台30 8标准电商 25保险产品
        if(self.bannerArray.count == 0) [self.bannerModel getHomeBannerDataWith:@"30"];
        if(self.navigationArray.count == 0) [self.navigationModel getHomeNavigationDataWith:@"30"];
        if(self.noticeArray.count == 0) [self.noticeModel getHomeNoticeDataWith:@"30"];
        if(self.recommendList.count == 0) [self.recommendModel getHomeRecommendData];
        
        NSString *unsaveGuide = EFUserDefaultsObjForKey(guidePrivacySave) ;
        if (ISEMPTY(unsaveGuide)) {
            [self.privacyCoverView setHidden:NO];
        }
//    }
    
    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];


}

- (void)getDataFinish:(BaseModel *)baseModel netError:(NSError *)error{
    
}

- (void)getDataFinish:(BaseModel *)baseModel netResponse:(BaseResponse *)response{
    if ([baseModel isKindOfClass:[HomeBannerModel class]])
    {
        HomeBannerResponse *resp = (HomeBannerResponse *)response;
        NSData *jsonData = [resp.resObject.menuJson dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        NSArray *array = dict[@"bannerList"];
        self.bannerArray = array;
        [self reloadBannerViewWith:array];
    }
    else if ([baseModel isKindOfClass:[HomeNavigationModel class]])
    {
        HomeNavigationResponse *resp = (HomeNavigationResponse *)response;
        NSData *jsonData = [resp.resObject.menuJson dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        NSArray *array = dict[@"bannerList"];
        self.navigationArray = array;
        [self.navigationScrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self setUpNavigationViewWith:array];
    }
    else if ([baseModel isKindOfClass:[HomeNoticeModel class]])
    {
        HomeNoticeResponse *resp = (HomeNoticeResponse *)response;
        NSData *jsonData = [resp.resObject.menuJson dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        NSArray *array = dict[@"bannerList"];
        self.noticeArray = array;
        [self setNoticeView];
    }
    else if ([baseModel isKindOfClass:[HomeRecommendModel class]])
    {
        HomeRecommendResponse *resp = (HomeRecommendResponse *)response;
        self.recommendList = resp.resObject;
        [self setUpRecommedView:resp.resObject];
    }
}

//接收到退出登录的通知
- (void)logoutNoti
{
//    [self.planDataArray removeAllObjects];
//    if ([self.view.subviews containsObject:self.healthAskBtn]) {
//        [self.healthAskBtn removeFromSuperview];
//    }
}

- (void)initView
{
    [super initView];
    
//    self.view.backgroundColor = kColorDefultBg;
    [self.view addSubview:self.statusOrangeView];
    [self.view addSubview:self.bannerBgView];
    [self.view addSubview:self.navigationScrollView];
    [self.view addSubview:self.noticeBgView];
    [self.view addSubview:self.recommednScrollView];
    
//    //获取banner配置：首页工作台30 8标准电商 25保险产品
//    [self.bannerModel getHomeBannerDataWith:@"30"];
//    [self.navigationModel getHomeNavigationDataWith:@"30"];
//    [self.noticeModel getHomeNoticeDataWith:@"30"];
//    [self.recommendModel getHomeRecommendData];
    
    /***没有引导过**/
    NSString *unsaveGuide = EFUserDefaultsObjForKey(guidePrivacySave) ;
//    if (ISEMPTY(unsaveGuide) && ![EFAppContext isUserLogin]) {
    if (ISEMPTY(unsaveGuide)) {
        [self showPrivacyDialog];
    }
//
//    /***检查版本更新**/
//    QueueStartAfterTime(10.0f)
//    [self.versonModel getVersionControlWithNowVersion:api_version_tag];
//    queueEnd
//
//
//    /**
//     * 用户退出登录 添加监听
//     */
//    EFNotificationAdd(logoutNoti, EFLogoutNoti)
//
//    /**
//     * 监听tableview的contentOffset 用来设置顶部的透明度
//     */
//    [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];

}

- (void)showPrivacyDialog{
    
    UIView *coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    coverView.userInteractionEnabled = YES ;
    _privacyCoverView = coverView;
    coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.41];
    [[UIApplication sharedApplication].keyWindow addSubview:coverView];

    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-280)/2, (SCREEN_HEIGHT-266)/2 , 280, 266)];
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView setCornerRedius:5];
    [coverView addSubview:bgView];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, bgView.width, 30)];
    titleLab.text = @"瑞星保用户协议及隐私政策";
    titleLab.textColor = kTitleColor_black;
    titleLab.font = kFontMidden;
    titleLab.textAlignment = NSTextAlignmentCenter;
    [bgView addSubview:titleLab];
    
    UILabel *thanks = [[UILabel alloc] initWithFrame:CGRectMake(28, titleLab.bottom+10, bgView.width-30, 14)];
    thanks.text = @"感谢您选择瑞星保！";
    thanks.textColor = kTitleColor_midden;
    thanks.font = KFontSmall;
    [bgView addSubview:thanks];
    
    UILabel *subTitle = [[UILabel alloc] initWithFrame:CGRectMake(27, thanks.bottom, bgView.width-54, 130)];
    subTitle.numberOfLines = 0;
    subTitle.text = @"我们非常重视您的个人信息和隐私保护，为了更好的保障您的个人权益，在使用我们的产品前，请务必审慎阅读《用户服务协议》和《用户隐私政策》内的所有条款，同意并接受全部条款后即可开始使用我们的服务。";
    subTitle.textColor = kTitleColor_midden;
    [subTitle setValue:@(20) forKey:@"lineSpacing"];
    subTitle.font = KFontSmall;
    [bgView addSubview:subTitle];
    
    NSRange range = NSMakeRange(49, 8) ;
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:subTitle.text];
    [str addAttribute:NSForegroundColorAttributeName value:kColorOrange range:range];
    subTitle.attributedText = str;
    
    NSRange range2 = NSMakeRange(58, 8) ;
    [str addAttribute:NSForegroundColorAttributeName value:kColorOrange range:range2];
    subTitle.attributedText = str;
    
    UIButton *serViceBtn = [[UIButton alloc]initWithFrame:CGRectMake(35, 145, 92, 24)];
    [serViceBtn addTarget:self action:@selector(serViceBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:serViceBtn];

    UIButton *privacyBtn = [[UIButton alloc]initWithFrame:CGRectMake(serViceBtn.right+25, serViceBtn.top, serViceBtn.width, serViceBtn.height)];
    [privacyBtn addTarget:self action:@selector(privacyBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:privacyBtn];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(4, subTitle.bottom+20, bgView.width, 1)];
    line.backgroundColor = kColorDefultBg;
    [bgView addSubview:line];
    
    UIView *btnView = [[UIView alloc]initWithFrame:CGRectMake(0, line.bottom, bgView.width, 40)];
    [bgView addSubview:btnView];

    UIButton *notAgreeBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, btnView.width*0.5, btnView.height)];
    [notAgreeBtn setTitle:@"不同意" forState:UIControlStateNormal];
    [notAgreeBtn.titleLabel setFont:kFontMidden];
    [notAgreeBtn setTitleColor:kTitleColor_midden forState:UIControlStateNormal];
    [notAgreeBtn addTarget:self action:@selector(notAgreeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:notAgreeBtn];
    
    UIView * verline = [[UIView alloc] initWithFrame:CGRectMake(notAgreeBtn.right, 0 , 1, btnView.height)];
    verline.backgroundColor = kColorDefultBg;
    [btnView addSubview:verline];

    UIButton *agreeBtn = [[UIButton alloc]initWithFrame:CGRectMake(verline.right, 0, btnView.width*0.5-1, btnView.height)];
    [agreeBtn setTitle:@"同意" forState:UIControlStateNormal];
    [agreeBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [agreeBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [agreeBtn addTarget:self action:@selector(agreeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:agreeBtn];
}

- (void)serViceBtnClick{
    [_privacyCoverView setHidden:YES];
    ServiceClauseController *serviceVC = [[ServiceClauseController alloc]init];
    [self.navigationController pushViewController:serviceVC animated:YES];
}

- (void)privacyBtnClick{
    [_privacyCoverView setHidden:YES];
    PrivcayClauseController *privacyVC = [[PrivcayClauseController alloc]init];
    [self.navigationController pushViewController:privacyVC animated:YES];
}

- (void)notAgreeBtnClick{
    [[UIApplication sharedApplication] performSelector:@selector(suspend)];
//    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    UIWindow *window = app.window;
//     // 动画 1
//    [UIView animateWithDuration:1.0f animations:^{
//        window.alpha = 0;
//        window.frame = CGRectMake(0, window.bounds.size.width, 0, 0);
//    } completion:^(BOOL finished) {
//        exit(0);
//    }];
}

- (void)agreeBtnClick{
    [self.privacyCoverView removeFromSuperview];
    EFUserDefaultsSetObj(@"agree", guidePrivacySave);
}

- (void)reloadBannerViewWith:(NSArray *)response
{
    NSMutableArray *urlArray = [NSMutableArray array];
    for(int i = 0; i < response.count; i++){
        NSDictionary *dic = response[i];
        [urlArray addObject:dic[@"bannerPic"]];
    }
    
    [self.bannerBgView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    EFAdView *adView = [EFAdView adScrollViewWithFrame:CGRectMake(0, 0, self.bannerBgView.width, self.bannerBgView.height) modelArray:urlArray imagePropertyName:@"imgurl" titlePropertyName:@"name"];
    __weak typeof(self) weakSelf = self;
    adView.callBack = ^(NSInteger index,id model){
        NSDictionary *dic = response[index];
        NSString *firstMenu = [NSString stringWithFormat:@"%@",dic[@"firstMenu"]];
        NSString *secondMenu = [NSString stringWithFormat:@"%@",dic[@"secondMenu"]];
        [JumpUtils jumpToSecondPage:weakSelf firstMenu:firstMenu secondMenu:secondMenu];
    };
    [self.bannerBgView addSubview:adView];
}

- (void)setUpNavigationViewWith:(NSArray *)array{
    
    CGFloat btnWidth = SCREEN_WIDTH / 4 ;
    CGFloat btnHeight = self.navigationScrollView.height;
    for (int i = 0 ; i < array.count; i++){
        NSDictionary *dic = array[i];
        HomeNavButton *relatedButton = [[HomeNavButton alloc]initWithFrame:CGRectMake(i*btnWidth+10,0, btnWidth, btnHeight)];
        [relatedButton setHimgName:dic[@"bannerPic"]];
        [relatedButton setTitleName:dic[@"secondMenuName"]];
        relatedButton.tag = 100 + i;
        [relatedButton addTarget:self action:@selector(relatedButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.navigationScrollView addSubview:relatedButton];
    }

    self.navigationScrollView.contentSize = CGSizeMake((btnWidth+10)*array.count,0);
}

- (void)relatedButtonClick:(UIButton *)btn{
    
    NSDictionary *dic = self.navigationArray[btn.tag-100];
    NSString *firstMenu = [NSString stringWithFormat:@"%@",dic[@"firstMenu"]];
    NSString *secondMenu = [NSString stringWithFormat:@"%@",dic[@"secondMenuUrl"]];
    [JumpUtils jumpToOtherPage:self firstMenu:firstMenu secondMenu:secondMenu thirdUrl:@""];
}

- (void)setNoticeView{
    
    [self.noticeView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

    NSMutableArray *titleArray = [NSMutableArray array];
    for (int i = 0; i<self.noticeArray.count; i++) {
        NSDictionary *dic = self.noticeArray[i];
        [titleArray addObject:dic[@"secondMenuName"]];
    }
    KKNoticeView *rollingView = [[KKNoticeView alloc] initWithFrame:CGRectMake(0, 0, self.noticeView.width-5, self.noticeView.height)];
    rollingView.delegate = self;
    [self.noticeView addSubview:rollingView];
    [rollingView startNoticeWithDataSource:titleArray];
}

- (void)KKNoticeView:(int)index{
    NSLog(@"======%d",index);
    NSDictionary *dic = self.noticeArray[index-1];
    NSString *firstMenu = [NSString stringWithFormat:@"%@",dic[@"firstMenu"]];
    NSString *secondMenu = [NSString stringWithFormat:@"%@",dic[@"secondMenu"]];
    [JumpUtils jumpToSecondPage:self firstMenu:firstMenu secondMenu:secondMenu];
}

- (void)setUpRecommedView:(NSArray *)array{
    for (NSDictionary *dic in array) {
        NSString *moduleType = [NSString stringWithFormat:@"%@",dic[@"moduleType"]];
        //资讯模块
        if(ISEqual(moduleType, @"1")){
            UIView *infoBgView = [[UIView alloc]initWithFrame:CGRectMake(10, self.recommednScrollView.contentSize.height, self.recommednScrollView.width-20, 10)];
            [self.recommednScrollView addSubview:infoBgView];
            
            UIView *leftLine = [[UIView alloc]initWithFrame:CGRectMake(0, 7, 3, 12)];
            [leftLine setCornerRedius:1];
            leftLine.backgroundColor = UIColorFromRGB1(0xE58580);
            [infoBgView addSubview:leftLine];
            
            UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, 300, 20)];
            titleLab.text = dic[@"myModuleTypeName"];
            titleLab.textColor = kTitleColor_black;
            titleLab.font = KFontSmall;
            [infoBgView addSubview:titleLab];
            
            CGFloat btnWidth = infoBgView.width / 2 ;
            CGFloat btnHeight = 100;
            NSArray *infoArray = dic[@"informationList"];
            self.informationList = infoArray;
            for (int i = 0 ; i < infoArray.count; i++){
                UIView *imageBgView = [[UIView alloc]initWithFrame:CGRectMake((i%2)*btnWidth,(i/2)*(btnHeight+10)+35, btnWidth, btnHeight)];
                [infoBgView addSubview:imageBgView];
                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(6,0, imageBgView.width-12, imageBgView.height)];
                imageView.tag = 100 + i;
                [imageView setCornerRedius:6];
                [imageView sd_setImageWithURL:[NSURL URLWithString:infoArray[i][@"indexPic"]] placeholderImage:kDefaultImage];
                [imageView addTapCallBack:self sel:@selector(recommedViewTap:)];
                [imageBgView addSubview:imageView];
            }
            infoBgView.height = ceil((double)infoArray.count/2) * (btnHeight+10)+40;
            self.recommednScrollView.contentSize = CGSizeMake(0, self.recommednScrollView.contentSize.height+infoBgView.height);
        }
        //标准电商
        else if(ISEqual(moduleType, @"8")){
            UIView *shopBgView = [[UIView alloc]initWithFrame:CGRectMake(10, self.recommednScrollView.contentSize.height, self.recommednScrollView.width-20, 10)];
            [self.recommednScrollView addSubview:shopBgView];
            
            UIView *leftLine = [[UIView alloc]initWithFrame:CGRectMake(0, 7, 3, 12)];
            [leftLine setCornerRedius:1];
            leftLine.backgroundColor = UIColorFromRGB1(0xE58580);
            [shopBgView addSubview:leftLine];
            
            UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, 300, 20)];
            titleLab.text = dic[@"myModuleTypeName"];
            titleLab.textColor = kTitleColor_black;
            titleLab.font = KFontSmall;
            [shopBgView addSubview:titleLab];
            
            CGFloat btnWidth = shopBgView.width / 2 ;
            CGFloat btnHeight = 100;
            NSArray *shopArray = dic[@"shopProductList"];
            self.shopProductList = shopArray;
            for (int i = 0 ; i < shopArray.count; i++){
                UIView *imageBgView = [[UIView alloc]initWithFrame:CGRectMake((i%2)*btnWidth,(i/2)*(btnHeight+10)+35, btnWidth, btnHeight)];
                [shopBgView addSubview:imageBgView];
                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(6,0, imageBgView.width-12, imageBgView.height)];
                imageView.tag = 1000 + i;
                [imageView setCornerRedius:6];
                [imageView sd_setImageWithURL:[NSURL URLWithString:shopArray[i][@"indexPic"]] placeholderImage:kDefaultImage];
                [imageView addTapCallBack:self sel:@selector(recommedViewTap:)];
                [imageBgView addSubview:imageView];
            }
            shopBgView.height = ceil((double)shopArray.count/2) * (btnHeight+10)+40;
            self.recommednScrollView.contentSize = CGSizeMake(0, self.recommednScrollView.contentSize.height+shopBgView.height);

        }
        //保险产品
        else if(ISEqual(moduleType, @"25")){
            UIView *productBgView = [[UIView alloc]initWithFrame:CGRectMake(10, self.recommednScrollView.contentSize.height, self.recommednScrollView.width-20, 10)];
            [self.recommednScrollView addSubview:productBgView];
            
            UIView *leftLine = [[UIView alloc]initWithFrame:CGRectMake(0, 7, 3, 12)];
            [leftLine setCornerRedius:1];
            leftLine.backgroundColor = UIColorFromRGB1(0xE58580);
            [productBgView addSubview:leftLine];
            
            UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, 300, 20)];
            titleLab.text = dic[@"myModuleTypeName"];
            titleLab.textColor = kTitleColor_black;
            titleLab.font = KFontSmall;
            [productBgView addSubview:titleLab];
            
            CGFloat btnWidth = productBgView.width /2 ;
            CGFloat btnHeight = 100;
            NSArray *productArray = dic[@"insuranceCangbaotuProductList"];
            self.insuranceCangbaotuProductList = productArray;
            for (int i = 0 ; i < productArray.count; i++){
                UIView *imageBgView = [[UIView alloc]initWithFrame:CGRectMake((i%2)*btnWidth,(i/2)*(btnHeight+10)+35, btnWidth, btnHeight)];
                [productBgView addSubview:imageBgView];
                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(6,0, imageBgView.width-12, imageBgView.height)];
                imageView.tag = 10000 + i;
                [imageView setCornerRedius:6];
                [imageView sd_setImageWithURL:[NSURL URLWithString:productArray[i][@"imageUrl"]] placeholderImage:kDefaultImage];
                [imageView addTapCallBack:self sel:@selector(recommedViewTap:)];
                [imageBgView addSubview:imageView];
            }
            productBgView.height = ceil((double)productArray.count/2) * (btnHeight+10)+40;
            self.recommednScrollView.contentSize = CGSizeMake(0, self.recommednScrollView.contentSize.height+productBgView.height);

        }
        
    }
}

- (void)recommedViewTap:(UITapGestureRecognizer *)tap{
    NSDictionary *dic;
    if(tap.view.tag >= 100 && tap.view.tag<1000){
        //资讯
        dic = self.informationList[tap.view.tag-100];
        InformationController *infoVC = [[InformationController alloc]init];
        infoVC.secondMenu = dic[@"id"];
        [self.navigationController pushViewController:infoVC animated:YES];
    }else if(tap.view.tag >= 1000 && tap.view.tag<10000){
        //标准电商
        dic = self.shopProductList[tap.view.tag-1000];
        GoodsDetailController *goodsDetailVC = [[GoodsDetailController alloc]init];
        goodsDetailVC.productId = dic[@"id"];
         [self.navigationController pushViewController:goodsDetailVC animated:YES];
    }else if(tap.view.tag >= 10000){
        //保险产品
        dic = self.insuranceCangbaotuProductList[tap.view.tag-10000];
        ProductDetailController *productDetaiVC = [[ProductDetailController alloc]init];
        productDetaiVC.secondMenu = dic[@"id"];
        [self.navigationController pushViewController:productDetaiVC animated:YES];
    }
}

- (UIView *)bannerBgView
{
    if (nil == _bannerBgView) {
        _bannerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, self.statusOrangeView.height, SCREEN_WIDTH, 160)];
        _bannerBgView.userInteractionEnabled = YES ;
    }
    return _bannerBgView ;
}

- (UIScrollView *)navigationScrollView
{
    if (nil == _navigationScrollView) {
        _navigationScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(10, self.bannerBgView.bottom+10, SCREEN_WIDTH-20, 96)];
        _navigationScrollView.delegate = self;
//        _navigationScrollView.alwaysBounceVertical = YES ;
        _navigationScrollView.showsVerticalScrollIndicator = NO ;
        _navigationScrollView.backgroundColor = kColorDefultCell;
    }
    return _navigationScrollView ;
}

- (UIView *)noticeBgView{
    
    if (nil == _noticeBgView) {
        _noticeBgView = [[UIView alloc] initWithFrame:CGRectMake(10, _navigationScrollView.bottom+10, SCREEN_WIDTH-20, 40)];
        [_noticeBgView setCornerRedius:5];
        _noticeBgView.backgroundColor = [UIColor whiteColor];

        UIImageView * noticeImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 12, 16, 16)];
        noticeImage.image = [UIImage imageNamed:@"image_notice.png"];
        [_noticeBgView addSubview:noticeImage];
        
        _noticeView = [[UIView alloc] initWithFrame:CGRectMake(noticeImage.right, 2, _noticeBgView.width-55, 35)];
        [_noticeBgView addSubview:_noticeView];
        
        UIImageView * rightImage = [[UIImageView alloc] initWithFrame:CGRectMake(_noticeBgView.width-22, 12, 16, 16)];
        rightImage.image = [UIImage imageNamed:@"image_right_orgin.png"];
        [_noticeBgView addSubview:rightImage];
        
    }
    return _noticeBgView;
}

- (HomeBannerModel *)bannerModel{

    if (nil == _bannerModel) {
        _bannerModel = [[HomeBannerModel alloc]initWithDelegate:self cache:NO];
    }
    return _bannerModel;
}

- (HomeNavigationModel *)navigationModel{

    if (nil == _navigationModel) {
        _navigationModel = [[HomeNavigationModel alloc]initWithDelegate:self cache:NO];
    }
    return _navigationModel;
}

- (NSArray *)navigationArray{
    if (nil == _navigationArray) {
        _navigationArray = [NSArray array];
    }
    return _navigationArray;
}

- (HomeNoticeModel *)noticeModel{

    if (nil == _noticeModel) {
        _noticeModel = [[HomeNoticeModel alloc]initWithDelegate:self cache:NO];
    }
    return _noticeModel;
}

- (HomeRecommendModel *)recommendModel{
    
    if (nil == _recommendModel) {
        _recommendModel = [[HomeRecommendModel alloc]initWithDelegate:self cache:NO];
    }
    return _recommendModel;
}

- (NSArray *)bannerArray{
    
    if (nil == _bannerArray) {
        _bannerArray = [NSArray array];
    }
    return _bannerArray;
}

- (NSArray *)noticeArray{

    if (nil == _noticeArray) {
        _noticeArray = [NSArray array];
    }
    return _noticeArray;
}

- (UIScrollView *)recommednScrollView{
    if(nil == _recommednScrollView){
        _recommednScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(10, self.noticeBgView.bottom+10, SCREEN_WIDTH-20, SCREEN_HEIGHT-KTarBarFullHeight-self.noticeBgView.bottom-10)];
        _recommednScrollView.showsVerticalScrollIndicator = NO;
        [_recommednScrollView setCornerRedius:5];
        _recommednScrollView.backgroundColor = [UIColor whiteColor];
        _recommednScrollView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
    }
    return _recommednScrollView;
}

- (NSArray *)informationList{
    
    if (nil == _informationList) {
        _informationList = [NSArray array];
    }
    return _informationList;
}

- (NSArray *)shopProductList{
    
    if (nil == _shopProductList) {
        _shopProductList = [NSArray array];
    }
    return _shopProductList;
}

- (NSArray *)recommendList{
    
    if (nil == _recommendList) {
        _recommendList = [NSArray array];
    }
    return _recommendList;
}

- (NSArray *)insuranceCangbaotuProductList{
    
    if (nil == _insuranceCangbaotuProductList) {
        _insuranceCangbaotuProductList = [NSArray array];
    }
    return _insuranceCangbaotuProductList;
}
@end
